<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<center>
    <font color="red" size="7">qq注册页面</font>
    <br/>
    <input name="username" onkeyup="kp(this)" type="text"/> <span id="sp"></span> <br/>
    <input name="password" type="password"/><br/>
    <input type="submit" value="注册"/>
</center>

<script type="text/javascript">

    function kp(ipt) {

        //获取input框中值
        var value = ipt.value;

        if (value != null && value != "") {

            var xml = new XMLHttpRequest();

            xml.onreadystatechange = function () {
                if (xml.readyState == 4 && xml.status == 200) {

                    var result = xml.responseText;

                    //1.找到span标签

                    var sp = document.getElementById("sp");

                    if (result == 1) {
                        //成功的 span 提示一句绿色的话
                        sp.innerHTML = "恭喜您!可以注册!!"; //清空
                        sp.style.color = "green";

                    } else {
                        //失败的 span 提示一句红色的话
                        sp.innerText = "用户已经被注册!";
                        sp.style.color = "red";
                    }
                }
            }
            xml.open("POST", "/usersd/exist");
            xml.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            xml.send("value=" + value)
        }


    }

</script>


</body>
</html>